<!-- techBack -->
<template>
  <div class="shareSetting content_box">
    <div class="header_row flex align-center flex-wrap" v-if="hasBtn('setting:query')">
      <div class="flex align-center m-r-2">
        <span>用户名称：</span>
        <el-input v-model="searchObj.UserName" placeholder="用户名称" clearable></el-input>
      </div>

      <div class="flex align-center m-r-2">
        <span>用户信息：</span>
        <!-- IconType -->
        <el-select v-model="searchObj.IconType" placeholder="请选择">
          <el-option v-for="item in comOptions" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </div>
      <div class="flex align-center m-r-2">
        <span>日期区间：</span>
        <el-date-picker v-model="searchObj.timeValue" type="daterange" range-separator="至" clearable value-format="yyyy-MM-dd HH:mm:ss" start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>
      </div>
      <el-button type="primary" @click="handleFilter">查询</el-button>
    </div>
    <div class="m-b-1 neck_box flex align-center space-between">
      <div>
        <!-- <el-button type="danger">批量删除</el-button> -->
        <el-button type="warning" disabled v-if="hasBtn('setting:export')">导出列表</el-button>
      </div>
      <pagination v-show="total > 0" :total="total" :page.sync="listQuery.PageIndex" :limit.sync="listQuery.PageSize" @pagination="getList" />
    </div>
    <el-table class="m-b-1" v-loading="listLoading" :data="list" @sort-change="sortChange" border stripe style="width: 100%">
      <el-table-column type="index" label="序号" align="center" fixed>
      </el-table-column>
      <!-- <el-table-column prop="date" label="单号" align="center">
      </el-table-column> -->
      <el-table-column prop="UserName" label="用户名" width="130" align="center" sortable>
      </el-table-column>
      <el-table-column prop="IconType" label="二维码类型" align="center" width="130" sortable>
        <template slot-scope="{ row }">
          <div>
            {{ getTypeName(row.IconType) }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="二维码" align="center" width="150" sortable>
        <template slot-scope="scope">
          <img width="60px" height="60px" :src="scope.row.Path" alt="" @click="handlePictureCardPreview(scope.row.Path)">
        </template>
      </el-table-column>
      <el-table-column prop="Path" label="二维码地址" align="left" sortable>
      </el-table-column>
      <el-table-column label="操作" align="center" width="150" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" type="danger" @click="del(scope.$index,scope.row.Id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog :visible.sync="dialogVisible" width="50%">
      <img style="width:50%; position: relative; left: 50%; transform: translateX(-50%);" :src="dialogImageUrl" alt="" />
    </el-dialog>
  </div>
</template>

<script>
  import { getList, delShare } from '@/api/ShareSetting/share'
  import Pagination from '@/components/Pagination'
  import { deepClone } from '@/utils'
  import { mapState } from 'vuex'
  export default {
    //import引入的组件需要注入到对象中才能使用
    name: 'shareSetting',
    components: { Pagination },
    data() {
      //这里存放数据
      return {
        dialogImageUrl: '',
        dialogVisible: false,
        comOptions: [
          {
            value: 0,
            label: '全部'
          },
          {
            value: 1,
            label: '商场二维码'
          },
          {
            value: 2,
            label: '云管家二维码'
          },
        ],
        list: [],
        total: 0,
        listLoading: true,
        searchObjTmpl: {},
        searchObj: {
          UserName: '',
          timeValue: '',
          IconType: 0,
        },
        listQuery: {
          PageIndex: 1,
          PageSize: 10,
          IsPaging: true, //是否分页
          SortName: 'CreateDate',
          SortType: false
        },
      };
    },
    //监听属性 类似于data概念
    computed: {},
    //监控data中的数据变化
    watch: {},
    created() {
      this.searchObjTmpl = deepClone(this.searchObj)
      this.getList()
    },
    activated() { },
    //方法集合
    methods: {
      handlePictureCardPreview(file) {
        //图片放大
        this.dialogImageUrl = file;
        this.dialogVisible = true;
      },
      getTypeName(type) {
        let name = this.comOptions.find(_ => _.value == type)
        return name.label
      },

      sortChange(data) {
        const { prop, order } = data
        this.listQuery.SortName = prop
        if (order === 'ascending') {
          this.listQuery.SortType = true
        } else {
          this.listQuery.SortType = false
        }
        this.handleFilter()
      },
      handleFilter() {
        this.listQuery.PageIndex = 1
        this.getList()
      },
      getQuery() {
        const params = {
          ...this.searchObj,
          ...this.listQuery,
        }
        return params
      },
      async getList() {
        this.listLoading = true
        const params = this.getQuery()
        if (params.timeValue && params.timeValue.length) {
          params.StartTime = params.timeValue[0]
          params.EndTime = params.timeValue[1]
        }
        const { Data, Total } = await getList(params)
        this.listLoading = false
        this.list = Data || []
        this.total = Total || 0
      },
      del(index, id) {
        this.$confirm('确认删除此条数据吗？').then(_ => {
          let obj = {
            Id: id
          }
          delShare(obj).then(res => {
            this.$notify({
              title: '删除成功',
              message: 'success',
              type: 'success',
              duration: 2000
            })
            this.list.splice(index, 1)
            this.total -= 1
          })
        })
      },
    }
  }
</script>
//@import url(); 引入公共css类
<style  scoped>
</style>
